#include "defines.h"
#include "lib.h"
#include "serial.h"

void putc(int c)
{
    if (c == '\n')
        serial_send_byte('\r');
    serial_send_byte(c);
}

void puts(const char *str)
{
    while (*str)
        putc(*str++);
}

void putval(unsigned long value, int column)
{
    char buf[11];
    int len;

    len = ltos(value, buf);

    for (; column > len; column--) {
        putc('0');
    }

    puts(buf);
}

void putxval(unsigned long value, int column)
{
    char buf[9];
    int len;

    len = xtos(value, buf);

    for (; column > len; column--) {
        putc('0');
    }

    puts(buf);
}

void putsigned(long num)
{
    if (num >= 0) {
        putval(num, 0);
    } else {
        putc('-');
        putval(-num, 0);
    }
}
